<?php

require_once 'Pipes/Config.php';
require_once 'Pipes/View.php';

class Pipes_Generator_Create_Model_Mapper
{
    private $_projectPath = '';
    private $_view = null;

    public function __construct($projectPath) {
        $this->_projectPath = $projectPath;

        $config = new Pipes_Config(array('projects' => array('PipesCore')));
        $this->_view = new Pipes_View($config, 'GeneratorTemplates');
        $this->_view->project = basename($this->_projectPath);
        $this->_view->generatingClass = __CLASS__;
    }
    public function create($name) {
        $this->_view->name = $name;
        $class = "<?php\n" . $this->_view->render('model/mapper')->toString();

        $fp = fopen("{$this->_projectPath}/Models/Mappers/{$name}Mapper.php", 'x+');
        fwrite($fp, $class);
        fclose($fp);
    }
}
